package pkg

import (
	"api-gateway/basic/inits"
	"context"
	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
	"log"
)

func Minio(name string, dst string) error {
	ctx := context.Background()
	minioConfig := inits.Config.Minio
	//  MinIO 服务地址
	endpoint := minioConfig.Endpoint
	//  AccessKey
	accessKeyID := minioConfig.AccessKeyID
	// SecretAccessKey
	secretAccessKey := minioConfig.SecretAccessKey
	// 1. 初始化 MinIO 客户端（核心步骤，后续所有方法都依赖此客户端）
	client, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
		Secure: false,
	})
	if err != nil {
		log.Fatalf("初始化客户端失败: %v", err)
	}
	log.Println(client)
	objectName := name
	filePath := dst
	contentType := "application/octet-stream"
	bucketName := "hospital"
	// Upload the test file with FPutObject
	_, err = client.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
	if err != nil {
		log.Fatalln(err)
	}
	return err
}
